package com.wlsk.license.common.converter;

import cn.idev.excel.converters.Converter;
import cn.idev.excel.enums.CellDataTypeEnum;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;

public abstract class BaseEnumConverter<T> implements Converter<T> {

    /**
     * 子类实现：根据 code 获取中文描述
     */
    protected abstract String getDescByCode(T code);

    @Override
    public WriteCellData<String> convertToExcelData(
            T value,
            ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) {
        String desc = getDescByCode(value);
        return new WriteCellData<>(desc == null ? "" : desc);
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING; // Excel 中显示为文本
    }
}
